﻿
function submit() {
    var UserID = encodeURI($("input[id*='txtUserID']").val());
    var UserName = encodeURI($("input[id*='txtUserName']").val());
    var FirstName = encodeURI($("input[id*='txtFirstName']").val());
    var LastName = encodeURI($("input[id*='txtLastName']").val());
    var EmailAddress = encodeURI($("input[id*='txtEmailAddress']").val());
    var Phone = encodeURI($("input[id*='txtPhone']").val());
    var DepartMent = encodeURI($("input[id*='txtDepartMent']").val());

    if (UserName.length == 0) {
        alert("用户名不能为空!");
        $("input[id*='txtUserName']").attr("focus", "true");
        return;
    }

    //开始发送数据
    $.ajax
                ({ //请求处理页
                    url: "Form.aspx", //处理页
                    dataType: "html",
                    //传送请求数据
                    data: {
                        UserID: UserID,
                        UserName: UserName,
                        FirstName: FirstName,
                        LastName: LastName,
                        EmailAddress: EmailAddress,
                        Phone: Phone,
                        DepartMent: DepartMent,
                        Type:"Save"
                    },
                    success: function (returnValue) { //成功后返回的数据
                        //根据返回值进行状态显示
                        if ($.trim(returnValue)=="True") {//注意是True,不是true
                            alert("success save!");
                            $('[id$=btnSearch]').click();
                        }
                        else {
                            alert("failure save!" + returnValue);
                        }
                    }
                })
            }

 function UserNameCheck(controlSelf) {
                if (controlSelf.value == "") {
                    changeBackgroundYe(controlSelf, 'false');
                    return;
                }

                //check if UserName is exists
                //开始发送数据
                var UserName = encodeURI(controlSelf.value);
                $.ajax
                ({ //请求处理页
                    url: "Form.aspx", //处理页
                    dataType: "html",
                    //传送请求数据
                    data: {
                        UserName: UserName,
                        Type: "Exists"
                    },
                    success: function (returnValue) { //成功后返回的数据
                        //根据返回值进行状态显示
                        if ($.trim(returnValue) == "True") {//注意是True,不是true

                            controlSelf.value = "";
                            //this name has been used
                            changeBackgroundRed(controlSelf, 'false');
                            alert("这个用户名已存在!" + UserName);

                        }
                        else {
                            //allow this name
                            changeBackgroundRed(controlSelf, 'true');
                        }
                    }
                })
            }